package demo5;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 阿宾
 * Date: 2024-06-05
 * Time: 15:40
 */
class Shape{
    public void draw(){
        System.out.println("画图形！！");
    }
}
class Rect extends Shape{
    @Override
    public void draw() {
        System.out.println("画矩形");
    }
}
class Cycle extends Shape{
    @Override
    public void draw() {
        System.out.println("画圆");
    }
}
class Flower extends Shape{
    @Override
    public void draw() {
        System.out.println("画花");
    }
}

public class Test {
    public static void drawShapes(){
        Cycle cycle = new Cycle();
        Rect rect = new Rect();
        Flower flower = new Flower();
        Shape[] shapes = {cycle,rect,flower,rect};//发生向上转型

        for (Shape shape: shapes) {
            shape.draw();
        }
    }

    public static void main(String[] args) {
        drawShapes();
    }
}
